// Copyright 2025 gll
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import type { Component } from "vue";
import type { TagProps, Placement } from "element-plus";
import type { autocompleteList } from "./paramsConfig";

export interface Props {
  model: any;
  rules?: any[];
  labelWidth?: string | number;
  labelPosition?: "left" | "right";
  labelSuffix?: string;
  rowGutter?: number;
  rowJustify?: string;
  rowAlign?: string;
  rowTag?: string;
  colSpans?: number;
  hideRequiredAsterisk?: boolean;
  requireAsteriskPosition?: "left" | "right";
  showMessage?: boolean;
  inlineMessage?: boolean;
  statusIcon?: boolean;
  validateOnRuleChange?: boolean;
  size?: "" | "large" | "default" | "small";
  disabled?: boolean;
  scrollToError?: boolean;
  scrollIntoViewOptions?: boolean;
  [k: string]: any;
}

export interface ColBox {
  /* col */
  colSpan?: string;
  colOffset?: number;
  colPush?: number;
  colPull?: number;
  colXs?: number;
  colSm?: number;
  colMd?: number;
  colLg?: number;
  colXl?: number;
  colTag?: string;

  prop: string;
  formRules?: any[];
  formLabel?: string;
  formLabelWidth?: string | number;
  formLabelPosition?: "left" | "right";
  formRequired?: boolean;
  formError?: string;
  formShowMessage?: boolean;
  formInlineMessage?: boolean;
  formSize?: "" | "large" | "default" | "small";
  formFor?: string;
  formValidateStatus?: "" | "error" | "validating" | "success";
}

export interface Default {
  type:
    | "text"
    | "textarea"
    | "password"
    | "number"
    | "inputtag"
    | "button"
    | "checkbox"
    | "file"
    | "radio"
    | "radiogroup"
    | "radiobuttongroup"
    | "select"
    | "selectGroup"
    | "year"
    | "years"
    | "month"
    | "months"
    | "date"
    | "dates"
    | "datetime"
    | "week"
    | "datetimerange"
    | "daterange"
    | "monthrange"
    | "yearrange"
    | "timepicker"
    | "timeselect"
    | "treeaelect"
    | "colorpicker";

  /* form元素 */
  model: string;
  id?: string;
  name?: string;

  placeholder?: string;
  clearable?: boolean;
  disabled?: boolean;
  prefixIcon?: string | Component;
  suffixIcon?: string | Component;
  autocomplete?: autocompleteList;
  readonly?: boolean;
  max?: number | string;
  min?: number | string;
  step?: any;
  size?: "" | "large" | "default" | "small";
  resize?: "none" | "both" | "horizontal" | "vertical";
  autofocus?: boolean;
  form?: string;
  ariaLabel?: string;
  tabindex?: string | number;
  validateEvent?: boolean;
  isComposing?: any;
  class?: string;
}

/* 文本输入 */
export interface Text extends Default {
  maxlength?: string | number;
  minlength?: string | number;
  showWordLimit?: boolean;
  formatter?: Function;
  parser?: Function;
  size?: "" | "large" | "default" | "small";
  inputStyle?: object;
  prefixSlotName?: string;
  suffixSlotName?: string;
  prependSlotName?: string;
  appendSlotName?: string;

  blur?: Function;
  focus?: Function;
  change?: Function;
  input?: Function;
  clear?: Function;
}

/* 文本域 */
export interface Textarea extends Default {
  maxlength?: string;
  minlength?: string;
  showWordLimit?: boolean;
  rows?: number;
  autosize?: boolean | object;
  inputStyle?: string | object;
  resizeTextarea?: Function;
  textareaStyle?: object;
  blur?: Function;
  focus?: Function;
  change?: Function;
  input?: Function;
  clear?: Function;
}
/* 密码输入 */
export interface Password extends Default {
  maxlength?: string | number;
  minlength?: string | number;
  showPassword?: boolean;
  inputStyle?: string | object;
}
/* 数字输入 */
export interface Number extends Default {
  stepStrictly?: boolean;
  precision?: number;
  controls?: boolean;
  controlsPosition?: "" | "right";
  valueOnClear?: number | null | "min" | "max";
  max?: number;
  min?: number;
  decreaseIcon?: any;
  increaseIcon?: any;
  prefix?: any;
  suffix?: any;
}
/* inputTag */
export interface InputTag extends Default {
  max?: number;
  //   tagType?: "" | "success" | "info" | "warning" | "danger";
  tagType?: TagProps["type"];
  //   tagEffect?: "" | "light" | "dark" | "plain";
  tagEffect?: TagProps["effect"];
  trigger?: "Enter" | "Space";
  draggable?: boolean;
  delimiter?: string | RegExp;
  saveOnBlur?: boolean;
  maxlength?: string | boolean;
  minlength?: string | boolean;
  tagSlotName?: string;
  prefixSlotName?: string;
  suffixSlotName?: string;
}
/* 单选按钮 */
export interface Radio extends Default {
  defaultSlotName?: string;
  options?: [
    {
      value?: string | number | boolean;
      label?: string | number | boolean;
      disabled?: boolean;
      name?: string;
      border?: boolean;
      size?: "large" | "default" | "small";
    }
  ];
}

export interface RadioGroup extends Default {
  size?: "large" | "default" | "small";
  disabled?: boolean;
  validateEvent?: boolean;
  ariaLabel?: string;
  name?: string;
  id?: string;
  defaultSlotName?: string;

  options?: {
    labelName?: string;
    valueName?: string;
    value?: string | number | boolean;
    label?: string | number | boolean;
    disabled?: boolean;
    name?: string;
    border?: boolean;
    size?: "large" | "default" | "small";
  }[];
}

export interface RadioButtonGroup extends Default {
  size?: "large" | "default" | "small";
  disabled?: boolean;
  validateEvent?: boolean;
  ariaLabel?: string;
  defaultSlotName?: string;
  options?: {
    value?: string | number | boolean;
    label?: string | number | boolean;
    disabled?: boolean;
    name?: string;
    textColor?: string;
    fill?: string;
  }[];
}

/* 下拉菜单 */
export interface Select extends Default {
  multiple?: boolean;
  valueKey?: string;
  collapseTags?: boolean;
  collapseTagsTooltip?: boolean;
  multipleLimit?: number;
  effect?: "dark" | "light";
  filterable?: boolean;
  allowCreate?: boolean;
  filterMethod?: Function;
  remote?: boolean;
  remoteMethod?: Function;
  remoteShowSuffix?: boolean;
  loading?: boolean;
  loadingText?: string;
  noMatchText?: string;
  noDataText?: string;
  popperClass?: string;
  reserveKeyword?: boolean;
  defaultFirstOption?: boolean;
  teleported?: boolean;
  appendTo?: string | Element;
  persistent?: boolean;
  automaticDropdown?: boolean;
  clearIcon?: string | object | Component;
  fitInputWidth?: boolean;
  suffixIcon?: string | object | Component;
  tagType?: TagProps["type"];
  tagEffect?: TagProps["effect"];
  offset?: number;
  showArrow?: boolean;
  placement?: Placement;
  fallbackPlacements?: ["bottom-start", "top-start", "right", "left"];
  maxCollapseTags?: number;
  popperOptions?: any;
  emptyValues?: Array<any> | null;
  valueOnClear?: any;
  tabindex?: string | number;
  optionsGroup?: {
    labelName?: string;
    label?: string;
    disabled?: boolean;
    options?: {
      valueName?: string;
      value?: any;
      labelName?: string;
      label?: any;
      disabled?: boolean;
    }[];
  }[];
  options?: {
    valueName?: string;
    value?: any;
    labelName?: string;
    label?: any;
    disabled?: boolean;
  }[];
  defaultSlotName?: string;
  headerSlotName?: string;
  footerSlotName?: string;
  prefixSlotName?: string;
  emptySlotName?: string;
  tagSlotName?: string;
  loadingSlotName?: string;
  labelSlotName?: string;
}

interface TimeDefault extends Default {
  readonly?: boolean;
  size?: "" | "large" | "default" | "small";
  editable?: boolean;
  startPlaceholder?: string;
  endPlaceholder?: string;
  popperClass?: string;
  popperOptions?: any;
  rangeSeparator?: string;
  defaultValue?: Date | [Date, Date];
  defaultTime?: Date | [Date, Date];
  format?: string;
  valueFormat?: string;
  unlinkPanels?: boolean;
  prefixIcon?: string | object | Component;
  clearIcon?: string | object | Component;
  disabledDate?: Function;
  shortcuts?: Array<{ text: string; value: Date | Function }>;
  cellClassName?: Function | string;
  teleported?: boolean;
  emptyValues?: any[];
  valueOnClear?: any;
  placement?: Placement;
  fallbackPlacements?: ["bottom-start", "top-start", "right", "left"];
  // [k: string]: any;
}

/* 时间年月日 */
export interface DateTimePicker extends TimeDefault {
  arrowControl?: boolean;
  dateFormat?: string;
  timeFormat?: string;
  showNow?: boolean;
  defaultSlotName?: string;
  rangeSeparatorSlotName?: string;
  prevMonthSlotName?: string;
  nextMonthSlotName?: string;
  prevYearSlotName?: string;
  nextYearSlotName?: string;
  change?: Function;
  blur?: Function;
  focus?: Function;
  clear?: Function;
  calendarChange?: Function;
  visibleChange?: Function;
}

/* 时间选择器时分秒 */
export interface TimePicker extends TimeDefault {
  editable?: boolean;
  isRange?: boolean;
  arrowControl?: boolean;
  disabledHours?: Function;
  disabledMinutes?: Function;
  disabledSeconds?: Function;
}

/* 选择或输入日期 */
export interface TimeSelect extends TimeDefault {
  includeEndTime?: boolean;
  effect?: TagProps["effect"];
  start?: string;
  end?: string;
  step?: string;
  minTime?: string;
  maxTime?: string;
}

/* 颜色选择器 */
export interface ColorPicker extends Default {
  showAlpha?: false;
  colorFormat?: "hsl" | "hsv" | "hex" | "rgb" | "hex" | "rgb";
  predefine?: string[];
  teleported?: true;
  popperClass?: string;
  change?: Function;
  activeChange?: Function;
  focus?: Function;
  blur?: Function;
}

type mergeInterface = Default &
  ColBox &
  Text &
  Textarea &
  Password &
  Number &
  InputTag &
  Radio &
  Select &
  DateTimePicker &
  TimePicker &
  TimeSelect;

export interface Form extends Props {
  formItem?: Array<mergeInterface>;
}
